package com.huike.pmps.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.huike.pmps.model.dto.cockpit.admin.PaymentCollectionLineAdminDTO;
import com.huike.pmps.model.dto.cockpit.province.PaymentCollectionLineProvinceDTO;
import com.huike.pmps.model.dto.cockpit.region.PaymentCollectionLineRegionDTO;
import com.huike.pmps.model.entity.PaymentCollection;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 作者：谌贵斌(黑桃K)
 * 日期: 2888-08-08
 * 老师QQ: 272488352
 * 官方QQ交流群: 377748272
 * 刀客程序员官网：http://www.daoke360.com
 * 刀客程序员淘宝旗舰店：https://daoke360.taobao.com/
 */
public interface PaymentCollectionDao extends BaseMapper<PaymentCollection> {

    @Insert({
            "<script>",
            "insert into p_payment_collection (",
            "  season,                         ",
            "  year,                           ",
            "  region_id,                      ",
            "  region_name,                    ",
            "  province_id,                    ",
            "  province_name,                  ",
            "  financial_year,                 ",
            "  collection_amount,               ",
            "  payment_date,                    ",
            "  product_type_id,                 ",
            "  product_type_name,               ",
            "  week_of_year,                    ",
            "  season_of_year,                  ",
            "  month_of_year,                   ",
            "  create_time                     ",
            ")values                           ",
            "<foreach collection='list' item='item' index='index' separator=','>",
            "(							",
            " #{item.season},           ",
            " #{item.year},             ",
            " #{item.regionId},        ",
            " #{item.regionName},      ",
            " #{item.provinceId},      ",
            " #{item.provinceName},    ",
            " #{item.financialYear},   ",
            " #{item.collectionAmount}, ",
            " #{item.paymentDate},      ",
            " #{item.productTypeId},     ",
            " #{item.productTypeName},    ",
            " #{item.weekOfYear},       ",
            " #{item.seasonOfYear},     ",
            " #{item.monthOfYear},      ",
            " #{item.createTime}       ",
            ")                          ",
            "</foreach >",
            "</script>",
    })
    int insertBatchList(List<PaymentCollection> list);


    /**
     * 省区 周期回款情况
     */
    @Select({
            "<script>",
            "select week_of_year week ,sum(collection_amount) collection_amount     ",
            "from `p_payment_collection`                                            ",
            "where province_id=#{provinceId} and `year`=#{year}                     ",
            "group by week_of_year                                                  ",
            "</script>",
    })
    List<PaymentCollectionLineProvinceDTO> selectProvincePaymentCollectAmount(Integer provinceId, Integer year);



    /**
     * 战区 周期回款情况
     */
    @Select({
            "<script>",
            "SELECT week_of_year week ,SUM(collection_amount) collection_amount ",
            "FROM p_payment_collection                                          ",
            "WHERE region_id=#{regionId} and `year`=#{year}                     ",
            "GROUP BY week_of_year                                              ",
            "</script>",
    })
    List<PaymentCollectionLineRegionDTO> selectRegionPaymentCollectAmount(Integer regionId, Integer year);


    /**
     * 战区 周期回款情况
     */
    @Select({
            "<script>",
            "SELECT week_of_year week ,SUM(collection_amount) collection_amount ",
            "FROM p_payment_collection                                          ",
            "WHERE `year`=#{year}                                               ",
            "GROUP BY week_of_year                                              ",
            "</script>",
    })
    List<PaymentCollectionLineAdminDTO> selectAdminPaymentCollectAmount(Integer year);
}
